<?php
header('Content-type:text/html;charset=utf-8');

//开启session
session_start();

//包含数据库配置
include '../public/peizhi.php';

//包含函数
include '../public/func.php';

//调用函数库
$link = db();

//接值板块ID
$bk_id = $_POST['bk_id'];
//接值标题
$title = $_POST['title'];
//接值内容
$content = $_POST['content'];
//获取当前时间
$time = time();
//接值验证码
/* $yanzheng = strtolower($_POST['yanzheng']);
$yzm = strtolower($_SESSION['yzm']); */

//判断用户是否登录
if(!empty($_SESSION['uname'])){
	//判断帖子标题是否为空
	if(!empty($title)){
		//判断帖子内容是否为空
		if(!empty($content)){
			$sql = "insert into fatie(bk_id,u_id,u_name,title,content,ft_time) values('{$bk_id}','{$_SESSION['uid']}','{$_SESSION['uname']}','{$title}','{$content}',{$time})";
		}else{
			exit("<script>alert('内容不能为空');window.location.href='./php/fatie.php?bk_id={$bk_id}';</script>");
		}
	}else{
		exit("<script>alert('标题不能为空');window.location.href='./php/fatie.php?bk_id={$bk_id}';</script>");
	}
}else{
	exit("<script>alert('用户未登录,请先登录账号');window.location.href='./php/fatie.php?bk_id={$bk_id}';</script>");
}

//判断验证码是否一致
/* if($yanzheng != $yzm){
	exit("<script>alert('验证码错误');window.location.href='./php/fatie.php?bk_id={$bk_id}';</script>");
} */

//判断执行语句跳转
if($res = mysqli_query($link,$sql)){
	echo "<script>alert('发表帖子成功');window.location.href='./php/liebiao.php?bk_id={$bk_id}';</script>";
}else{
	echo "<script>alert('发表帖子失败');window.location.href='./php/fatie.php?bk_id={$bk_id}';</script>";
}




